package com.wmc;

import com.commonfunction.CommFunction;
import com.databasefunction.AllDBFunction;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class WMCSavenSubmit extends ActionSupport{
	private String rstno,vehicleno,custname,address,commodity,brokername,ponum,nobags,grossweight,sysdate,tareweight,systime,netweight,userid,commisionname;
	String barcode;
	
	
	public String getRstno() {
		return rstno;
	}


	public void setRstno(String rstno) {
		this.rstno = rstno;
	}


	public String getVehicleno() {
		return vehicleno;
	}


	public void setVehicleno(String vehicleno) {
		this.vehicleno = vehicleno;
	}


	public String getCustname() {
		return custname;
	}


	public void setCustname(String custname) {
		this.custname = custname;
	}


	public String getAddress() {
		return address;
	}


	public void setAddress(String address) {
		this.address = address;
	}


	public String getCommodity() {
		return commodity;
	}


	public void setCommodity(String commodity) {
		this.commodity = commodity;
	}


	public String getBrokername() {
		return brokername;
	}


	public void setBrokername(String brokername) {
		this.brokername = brokername;
	}


	public String getPonum() {
		return ponum;
	}


	public void setPonum(String ponum) {
		this.ponum = ponum;
	}


	public String getNobags() {
		return nobags;
	}


	public void setNobags(String nobags) {
		this.nobags = nobags;
	}


	public String getGrossweight() {
		return grossweight;
	}


	public void setGrossweight(String grossweight) {
		this.grossweight = grossweight;
	}


	public String getSysdate() {
		return sysdate;
	}


	public void setSysdate(String sysdate) {
		this.sysdate = sysdate;
	}


	public String getTareweight() {
		return tareweight;
	}


	public void setTareweight(String tareweight) {
		this.tareweight = tareweight;
	}


	public String getSystime() {
		return systime;
	}


	public void setSystime(String systime) {
		this.systime = systime;
	}


	public String getNetweight() {
		return netweight;
	}


	public void setNetweight(String netweight) {
		this.netweight = netweight;
	}


	public String getUserid() {
		return userid;
	}


	public void setUserid(String userid) {
		this.userid = userid;
	}


	public String getCommisionname() {
		return commisionname;
	}


	public void setCommisionname(String commisionname) {
		this.commisionname = commisionname;
	}


	public String getBarcode() {
		return barcode;
	}


	public void setBarcode(String barcode) {
		this.barcode = barcode;
	}


	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		String userrole = (String) ActionContext.getContext().getSession().get("userrole"); 
		if ((null != userrole) && (userrole.equals("weightmachine") || userrole.equals("admin") || userrole.equals("superadmin"))) {
		
		}else
			return "unauthorised";
		
		
		AllDBFunction allDBFunction = new AllDBFunction();
		CommFunction commFunction = new CommFunction();
		System.out.println(commFunction.formatDateForDb(sysdate));
		int sysdateint = commFunction.formatDateForDb(sysdate);
		if(null!=netweight && netweight.equals("")){
			allDBFunction.update(barcode.toLowerCase(), brokername, custname, commisionname, rstno, vehicleno, commodity, nobags, ponum, grossweight, tareweight, netweight, sysdateint, "","" , "", "", "", "", "", userid, "", "", "", "", "", "", "", "", "", "", "", "", "",address,systime, 0);
		}
		else{
			allDBFunction.update(barcode.toLowerCase(), brokername, custname, commisionname, rstno, vehicleno, commodity, nobags, ponum, grossweight, tareweight, netweight, sysdateint, "","" , "", "", "", "", "", userid, "", "", "", "", "", "", "", "", "", "", "", "", "",address,systime, 1);
			allDBFunction.addAnalysisTodb(barcode.toLowerCase());
		}
		addActionMessage("Entry successful");
		return "success";
		
	}
}
